<template>
    <div class="app-container">
      <div class="block">
        <el-row  :gutter="24">

          <el-col :span="4">
            <el-select v-model="listQuery.communityId" placeholder="选择社区" @change="getCustsSearch">
              <el-option
                v-for="item in options.communitys"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <el-select v-model="listQuery.quoteType" placeholder="选择报价类型">
              <el-option
                v-for="item in options.quotes"
                :key="item.k"
                :label="item.v"
                :value="item.k">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <el-select v-model="listQuery.yesOrNo" placeholder="是否有效">
              <el-option
                v-for="item in options.yesOrNo"
                :key="item.k"
                :label="item.v"
                :value="item.k">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="8">
            <el-button type="success" icon="el-icon-search" @click.native="search">{{ $t('button.search') }}</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click.native="reset">{{ $t('button.reset') }}</el-button>
          </el-col>
        </el-row>
        <br>
      </div>


        <div class="block">
            <el-row>
                <el-col :span="24">
                    <el-button type="success" icon="el-icon-plus" @click.native="add">{{ $t('button.add') }}</el-button>
                    <!--<el-button type="primary" icon="el-icon-edit" @click.native="edit">{{ $t('button.edit') }}</el-button>-->
                    <el-button type="danger" icon="el-icon-delete" @click.native="remove">{{ $t('button.delete') }}</el-button>
                </el-col>
            </el-row>
        </div>


        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row
                  @current-change="handleCurrentChange">
            <el-table-column label="社区名称"  align="center">
              <template slot-scope="scope">
                {{scope.row.communityName}}
              </template>
            </el-table-column>
            <el-table-column label="车位编号" align="center">
              <template slot-scope="scope">
                <a class="button" style="color:blue" @click="queryParking(scope.row.parkingId)">{{scope.row.parkingCode}}</a>
              </template>
            </el-table-column>
            <el-table-column label="客户名称"  align="center">
                <template slot-scope="scope">
                  <a class="button" style="color:blue" @click="queryCust(scope.row.custId)">{{scope.row.custName}}</a>
                </template>
            </el-table-column>
            <el-table-column label="报价类型"  align="center">
                <template slot-scope="scope">
                    {{scope.row.quoteTypeName}}
                </template>
            </el-table-column>
            <el-table-column label="报价金额"  align="center">
                <template slot-scope="scope">
                  {{scope.row.quotePrice}} 元/{{scope.row.quoteRange}}{{scope.row.quoteUnitName}}
                </template>
            </el-table-column>
            <!--<el-table-column label="合同周期" align="center">
                <template slot-scope="scope">
                    {{scope.row.realRange}}
                </template>
            </el-table-column>-->
            <el-table-column label="合同金额" align="center">
              <template slot-scope="scope">
                {{scope.row.realPrice}} 元
              </template>
            </el-table-column>
            <el-table-column label="签订日期" align="center">
                <template slot-scope="scope">
                    {{scope.row.signDateStr}}
                </template>
            </el-table-column>
            <el-table-column label="开始日期" align="center">
                <template slot-scope="scope">
                    {{scope.row.startDateStr}}
                </template>
            </el-table-column>
            <el-table-column label="结束日期" align="center">
                <template slot-scope="scope">
                    {{scope.row.endDateStr}}
                </template>
            </el-table-column>
            <el-table-column label="合同文件" align="center">
                <template slot-scope="scope">
                  <a :href="scope.row.contractFileUrl" target="_blank" class="button" style="color:blue">点击打开</a>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-sizes="[10, 20, 50, 100,500]"
                :page-size="listQuery.limit"
                :total="total"
                @size-change="changeSize"
                @current-change="fetchPage"
                @prev-click="fetchPrev"
                @next-click="fetchNext">
        </el-pagination>

        <el-dialog
                :title="formTitle"
                :visible.sync="formVisible"
                width="70%">
            <el-form ref="form" :model="form" :rules="rules" label-width="150px">
                <el-row>
                    <el-col :span="12">
                      <el-form-item label="社区" prop="communityId">
                        <el-select v-model="form.communityId" placeholder="请选择" @change="getCustsAndParking">
                          <el-option
                            v-for="item in options.communitys"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="客户" prop="custId">
                        <el-select v-model="form.custId" placeholder="请选择"
                                   filterable :filter-method="custFilter" >
                          <el-option
                            v-for="item in options.custIds"
                            :key="item.custId"
                            :label="item.custName"
                            :value="item.custId">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="车位" prop="parkingId" >
                          <el-select v-model="form.parkingId" placeholder="请选择"
                                     filterable :filter-method="parkingFilter" @change="getQuotes">
                            <el-option
                              v-for="item in options.parkings"
                              :key="item.id"
                              :label="item.title"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="报价" prop="quoteId" >
                        <el-select v-model="form.quoteId" placeholder="请选择" @change="selectQuote">
                          <el-option
                            v-for="item in options.quotes"
                            :key="item.id"
                            :label="'【'+item.quoteTypeName+'】'+item.quotePrice + ' / ' + item.quoteRange + ' ' + item.quoteUnitName "
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12" v-show="false">
                        <el-form-item label="报价类型" >
                            <el-input v-model="form.quoteType" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-show="false">
                        <el-form-item label="报价周期"  >
                            <el-input v-model="form.quoteRange" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-show="false">
                        <el-form-item label="报价周期单位"  >
                            <el-input v-model="form.quoteUnit" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                   <!-- <el-col :span="12" v-show="false">
                        <el-form-item label="合同周期"  >
                            <el-input v-model="form.realRange" minlength=1></el-input>
                        </el-form-item>
                    </el-col>-->
                    <el-col :span="12" >
                      <el-form-item label="合同金额" prop="realPrice" >
                        <el-input v-model.number="form.realPrice" minlength=1>
                          <template slot="append">元</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="签订日期" prop="signDate" >
                        <el-date-picker type="date" placeholder="选择日期" v-model="form.signDate" style="width: 100%;">

                        </el-date-picker>
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="开始日期" prop="startDate" >
                          <el-date-picker type="date" placeholder="选择日期" v-model="form.startDate" style="width: 100%;" >

                          </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <!--<el-col :span="12">
                        <el-form-item label="结束日期"  >
                          <el-date-picker type="date" placeholder="选择日期" v-model="form.endDate" style="width: 100%;">

                          </el-date-picker>
                        </el-form-item>
                    </el-col>-->

                    <el-col :span="12">
                        <el-form-item label="合同文件" prop="contractFileId" >
                            <el-input v-model="form.contractFileId" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="save">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="formVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>

            </el-form>
        </el-dialog>



        <el-dialog
          :title="viewParkingTitle"
          :visible.sync="viewParkingVisible"
          width="70%">
          <el-form label-width="150px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="社区" >
                  {{viewParking.communityName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="大楼" >
                  {{viewParking.buildingName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="房间" >
                  {{viewParking.roomName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="车位编号">
                  {{viewParking.code}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="车位名称" >
                  {{viewParking.name}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="车位位置">
                  {{viewParking.position}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="租售方式" >
                  {{viewParking.ownerFlagName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="车位类型" >
                  {{viewParking.parkingTypeName}}
                </el-form-item>
              </el-col>

            </el-row>
            <el-form-item>
              <el-button type="primary" @click.native="viewParkingVisible = false">{{ $t('button.close') }}</el-button>
            </el-form-item>

          </el-form>
        </el-dialog>


        <el-dialog
          :title="viewCustTitle"
          :visible.sync="viewCustVisible"
          width="70%">
          <el-form label-width="150px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名">
                  {{viewCust.name}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="手机号" >
                  {{viewCust.mobile}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件类型" >
                  {{viewCust.cardTypeName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件号码" >
                  {{viewCust.cardNo}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="性别">
                  {{viewCust.genderName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证注册地" >
                  {{viewCust.registeAddr}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="入住日期" >
                  {{viewCust.inDateStr}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="搬离日期" >
                  {{viewCust.outDateStr}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="客户类型" >
                  {{viewCust.ownerFlagName}}
                </el-form-item>
              </el-col>

            </el-row>
            <el-form-item>
              <el-button type="primary" @click.native="viewCustVisible = false">{{ $t('button.close') }}</el-button>
            </el-form-item>

          </el-form>
        </el-dialog>
    </div>
</template>

<script src="./parking_contract.js"></script>


<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/common.scss";
</style>

